﻿using System.Xml;

namespace Builderator.Core.Components
{
    public class BuildVersion
    {
        public int Major
        {
            get;
            set;
        }

        public int Minor
        {
            get;
            set;
        }

        public int Build
        {
            get;
            set;
        }

        public int Revision
        {
            get;
            set;
        }

        public BuildVersion()
        {
            this.Major = 0;

            this.Minor = 0;

            this.Build = 0;

            this.Revision = 0;
        }

        public BuildVersion(string settings)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(settings);

            XmlElement rootElement = xmlDoc.DocumentElement;

            this.Major = int.Parse(rootElement.GetAttribute("Major"));

            this.Minor = int.Parse(rootElement.GetAttribute("Minor"));

            this.Build = int.Parse(rootElement.GetAttribute("Build"));

            this.Revision = int.Parse(rootElement.GetAttribute("Revision"));
        }

        public override string ToString()
        {
            XmlDocument xmlDoc = new XmlDocument();

            XmlElement rootElement = xmlDoc.CreateElement("Version");

            rootElement.SetAttribute("Major", this.Major.ToString());

            rootElement.SetAttribute("Minor", this.Minor.ToString());

            rootElement.SetAttribute("Build", this.Build.ToString());

            rootElement.SetAttribute("Revision", this.Revision.ToString());

            xmlDoc.AppendChild(rootElement);

            return xmlDoc.InnerXml;
        }
    }
}
